package jp.syuriken.snsw.terenaibot.format.function;

import jp.syuriken.snsw.terenaibot.format.CompileArg;
import jp.syuriken.snsw.terenaibot.format.FormatSyntaxException;
import jp.syuriken.snsw.terenaibot.format.PrecompiledSyntaxGroup;

/**
 * TODO snsoftware
 * 
 * @author $Author: snswinhaiku.lo@gmail.com $
 */
public class IntLessThanEqualFunction extends AbstractFormatFunction {
	
	@Override
	public String getReturnValue(PrecompiledSyntaxGroup[] args, CompileArg compileArg) throws FormatSyntaxException {
		checkArgLength(args, compileArg, "lte", 2);
		String formatted = null;
		
		int a;
		try {
			formatted = args[0].format(compileArg);
			a = Integer.parseInt(formatted);
		} catch (NumberFormatException e) {
			throw new FormatSyntaxException("function<gte> can't parse integer: " + formatted + " (format:"
					+ args[0].toString() + ")");
		}
		int b;
		try {
			formatted = args[1].format(compileArg);
			b = Integer.parseInt(args[1].format(compileArg));
		} catch (NumberFormatException e) {
			throw new FormatSyntaxException("function<gte> can't parse integer: " + formatted + " (format:"
					+ args[0].toString() + ")");
			
		}
		if (a <= b) {
			return "true";
		} else {
			return "false";
		}
	}
}
